package com.artPreter.service.impl;


import com.artPreter.mapper.EventExhibitionMapper;
import com.artPreter.mapper.EventExhibitionTempMapper;
import com.artPreter.pojo.Depart;
import com.artPreter.pojo.EventExhibition;
import com.artPreter.pojo.EventExhibitionTemp;
import com.artPreter.pojo.EventExhibitionTemp;
import com.artPreter.service.IEventExhibitionTempService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 活动展览模板内容表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2025-01-06
 */
@Service
public class EventExhibitionTempServiceImpl extends ServiceImpl<EventExhibitionTempMapper, EventExhibitionTemp> implements IEventExhibitionTempService {

    @Autowired
    private EventExhibitionMapper eventExhibitionMapper;


    @Override
    public EventExhibitionTemp getEventExhibitionTemp(EventExhibitionTemp eventExhibitionTemp) {
        LambdaQueryWrapper<EventExhibitionTemp> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EventExhibitionTemp::getEventId,eventExhibitionTemp.getEventId());
        List<EventExhibitionTemp> list = this.baseMapper.selectList(lambdaQueryWrapper);
        System.out.println(eventExhibitionTemp.getEventId());
        if (list.size() == 0){
            EventExhibitionTemp result = new EventExhibitionTemp();
            String uuid = java.util.UUID.randomUUID().toString();
            result.setContentId(uuid);
            LambdaQueryWrapper<EventExhibition> departLambdaQueryWrapper = new LambdaQueryWrapper<>();
            departLambdaQueryWrapper.eq(EventExhibition::getEventId,eventExhibitionTemp.getEventId());
            List<EventExhibition> departList = eventExhibitionMapper.selectList(departLambdaQueryWrapper);
            if (departList.size() > 0){
                result.setName(departList.get(0).getName()+"模板");
                result.setEventId(departList.get(0).getEventId());
            }
            this.baseMapper.insert(result);
            return result;
        }else{
            return list.get(0);
        }
    }

    @Override
    public void saveEventExhibitionTemp(EventExhibitionTemp eventExhibitionTemp) {
        this.baseMapper.updateById(eventExhibitionTemp);
    }
}
